jQuery(function($) {
    var searchProductPreviousValue, liveProductSearchTimer
    $('.input-product-search').on('keyup', function(event) {
        var $parent = $(this).closest('.product-search-form');
        event.preventDefault();
        if (event.keyCode == 27) {
            $('.product-search-results').fadeOut(400);
            return;
        }
        if ($(this).val() != '') {
            $parent.find('.clear-search').show();
        } else {
            $parent.find('.clear-search').hide();
        }
    });
    
    $('.clear-search').on('click', function(event) {
        event.preventDefault()
        $(this).closest('.product-search-form').find('.input-product-search').val('').focus().keyup()
    });
});
